local meta = FindMetaTable("Player")
if not meta then return end

function meta:IsInQueue()
	for i, pl in ipairs(GAMEMODE.Queue) do
		if pl == self then 
			return i 
		end
	end
end

meta.SetLap = meta.SetFrags
meta.AddLap = meta.AddFrags
meta.GetLap = meta.Frags
meta.Lap = meta.Frags
meta.SetCheckpoint = meta.SetDeaths
meta.AddCheckpoint = meta.AddDeaths
meta.GetCheckpoint = meta.Deaths
meta.Checkpoint = meta.Deaths

function meta:SetHoverGear(veh)
	self:SetDTEntity(0, veh)
end

function meta:GetHoverGear()
	return self:GetDTEntity(0)
end

function meta:GetDistance()
	if IsValid(self:GetHoverGear()) then
		local yourpos = self:GetHoverGear():GetPos()
		local checkpoint = GAMEMODE.Checkpoints
		local nextcheckpoint = self:Deaths() + 2

		if nextcheckpoint > #checkpoint then
			nextcheckpoint = 0
		end

		if not yourpos then return 999999 end
		if not checkpoint then return 999999 end		
		if not checkpoint[nextcheckpoint] then return 999999 end

		if yourpos:Distance(checkpoint[nextcheckpoint]) then
			return yourpos:Distance(checkpoint[nextcheckpoint])
		else
			return 999999
		end
	else
		return 999999
	end
end

meta.OldSetTeam = meta.SetTeam
function meta:SetTeam(teamid)
	self:OldSetTeam(teamid)

	gamemode.Call("PlayerChangedTeam", self, self:Team(), teamid)
end

function meta:IsRacing()
	return self:Team() == TEAM_RACING
end
